package model;

import java.io.*;
import java.util.*;

import javax.xml.bind.*;

import model.environmentConfig.*;

public class XMLInterface{
	public static EnvironmentConfiguration loadXMLFile(String fileNamePath) throws JAXBException, IOException{
		JAXBContext context=JAXBContext.newInstance(EnvironmentConfiguration.class);
		Unmarshaller unmarshaller=context.createUnmarshaller();
		
		EnvironmentConfiguration envConf=(EnvironmentConfiguration) unmarshaller.unmarshal(new File(fileNamePath));
		
		return(envConf);
	}
	
	public static void saveXMLFile(String fileNamePath, EnvironmentConfiguration envConf) throws JAXBException, IOException{
		JAXBContext context=JAXBContext.newInstance(EnvironmentConfiguration.class);
		Marshaller marshaller=context.createMarshaller();
		
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		marshaller.marshal(envConf, new File(fileNamePath));
	}
	
	public static List<String> getConfigList(){
		List<String> results = new ArrayList<String>();
		File[] files = new File("./xmls").listFiles();

		for (File file : files) {
		    if (file.isFile()) {
		        results.add(file.getName());
		    }
		}
		return results;
	}
	
	public static List<String> getSubmittedList(){
		List<String> results = new ArrayList<String>();
		File[] files = new File("./submitted").listFiles();

		for (File file : files) {
		    if (file.isFile()) {
		        results.add(file.getName());
		    }
		}
		return results;
	}
	
	public static List<String> getApprovedList(){
		List<String> results = new ArrayList<String>();
		File[] files = new File("./approved").listFiles();

		for (File file : files) {
		    if (file.isFile()) {
		        results.add(file.getName());
		    }
		}
		return results;
	}
	
	public static List<String> getRejectedList(){
		List<String> results = new ArrayList<String>();
		File[] files = new File("./rejected").listFiles();

		for (File file : files) {
		    if (file.isFile()) {
		        results.add(file.getName());
		    }
		}
		return results;
	}
}
